package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

public class UserDatabase {

    private List<User> userList;

    public UserDatabase() {
        userList = new ArrayList<User>();
    }

    public UserDatabase(List<User> userList) {
        this.userList = userList;
    }

    public void addUser(String name, String email, String phone, String username, String password) {
        User user = new User(name, email, phone, username, password);
        userList.add(user);
    }

    public boolean validateUser(String username, String password) {
        User user = searchForUser(username);
        if (user != null) {
            return user.validatePassword(password);
        } else {
            System.out.println("User is not in our database.");
            return false;
        }

    }

    public User searchForUser(String username) {
        for (User user : userList) {
            if (user.getUsername().equals(username))
                return user;
        }
        return null;
    }

}
